package com.liu.service;

import com.liu.mapper.EmployeeMapper;
import com.liu.pojo.Employee;
import com.liu.pojo.EmployeeExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeService {
    @Autowired
    EmployeeMapper employeeMapper;
/**
 * @Description 查询所有员工
 * @Param []
 * @return java.util.List<com.liu.pojo.Employee>
 **/
    public List<Employee> getAll() {
       return employeeMapper.selectByExampleWithDept(null);
    }
/**
 * @Description 员工保存
 * @Param [employee]
 * @return void
 **/
    public void saveEmp(Employee employee) {
        employeeMapper.insertSelective(employee);
    }
/**
 * @Description 检查员工名是否可用
 * @Param [empName]
 * @return java.lang.Boolean
 **/
    public Boolean checkUser(String empName) {
        EmployeeExample example = new EmployeeExample();
        EmployeeExample.Criteria criteria = example.createCriteria();
        criteria.andEmpNameEqualTo(empName);
        long count = employeeMapper.countByExample(example);
        return count==0;
    }
/**
 * @Description 按照员工id查询员工信息
 * @Param [id]
 * @return com.liu.pojo.Employee
 **/
    public Employee getEmp(Integer id) {
        Employee employee = employeeMapper.selectByPrimaryKey(id);
        return employee;
    }
/**
 * @Description 员工更新
 * @Param [employee]
 * @return void
 **/
    public void updateEmp(Employee employee) {
        employeeMapper.updateByPrimaryKeySelective(employee);
    }
/**
 * @Description 员工删除
 * @Param [id]
 * @return void
 **/
    public void deleteEmp(Integer id) {
        employeeMapper.deleteByPrimaryKey(id);
    }

    public void deleteBatch(List<Integer> ids) {
        EmployeeExample example = new EmployeeExample();
        EmployeeExample.Criteria criteria = example.createCriteria();
        criteria.andEmpIdIn(ids);
        employeeMapper.deleteByExample(example);
    }
}
